#!/usr/bin/env bash
#
# Copyright 2014-2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in
#       the documentation and/or other materials provided with the
#       distribution.
#
#     * Neither the name of the copyright holder nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

#
# src/test/pmem_is_pmem_posix/TEST2 -- unit test for pmem_is_pmem
#

# standard unit test setup
. ../unittest/unittest.sh

require_test_type medium
require_fs_type none

setup

# single mm entry - 0x7fff77424000 2147479552
#
# 7fff77423000 2147479552
#	starts before mm entry, should produce: 0
# 7fff77423000 2147483648
#	starts before mm entry, should produce: 0
# 7fff77423000 8192
#	starts before mm entry, should produce: 0
# 7fff77423000 4096
#	starts before mm entry, should produce: 0
# 7fff77424000 2147479552
#	exactly matches mm entry, should produce: 1
# 7fff77424000 2147483648
#	extends past mm entry, should produce: 0
# 7fff77424000 8192
#	entirely encompassed by mm entry: should produce: 1
# 7fff77428000 10240
#	subset of mm entry: should produce: 1
# 7fff77423000 0
#	starts before mm entry, should produce: 0
# 7fff77424000 0
#	starts at mm entry: should produce: 1
# 7fff77424000 0xffffffffffffffff
#	extends past second mm entry, should produce: 0
# 7fff77423008 1
#	entirely encompassed by first mm entry: should produce: 0
# 7fff77423ff0 32
#	start at first mm entry, extends into second: should produce: 0

expect_normal_exit ./pmem_is_pmem_posix$EXESUFFIX\
	a 0x7fff77424000 2147479552 MAP_SYNC\
	\
	t 0x7fff77423000 2147479552\
	t 0x7fff77423000 2147483648\
	t 0x7fff77423000 8192\
	t 0x7fff77423000 4096\
	t 0x7fff77424000 2147479552\
	t 0x7fff77424000 2147483648\
	t 0x7fff77424000 8192\
	t 0x7fff77428000 10240\
	t 0x7fff77423000 0\
	t 0x7fff77424000 0\
	t 0x7fff77424000 0xffffffffffffffff\
	t 0x7fff77423008 1\
	t 0x7fff77423FF0 32

check

pass
